package com.epam.giorgadze.task3.entity.plane_type;

import com.epam.giorgadze.task3.entity.PlaneModel;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
import java.util.Comparator;

/**
 * User: Luka
 * Date: 06.02.14
 * Time: 11:33
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CargoPlane", propOrder = {
        "tonnage"
})
public class CargoPlane extends Plane {
    private double tonnage;

    public boolean checkTonnage(double d) {
        if (d >= 0) {
            return true;
        } else return false;
    }

    public CargoPlane() {
    }

    public CargoPlane(PlaneModel model, double travelingDistance, double fuelConsumption, double price, double lifespan, double tonnage) {
        super(model, travelingDistance, fuelConsumption, price, lifespan);
        if (checkTonnage(tonnage)) this.tonnage = tonnage;
    }

    public double getTonnage() {
        return tonnage;
    }

    public void setTonnage(double tonnage) {
        if (checkTonnage(tonnage)) this.tonnage = tonnage;
    }

    public static class TonnageComparator implements Comparator<CargoPlane> {
        public static final Comparator<CargoPlane> TONNAGE_ORDER = new TonnageComparator();

        public int compare(CargoPlane c1, CargoPlane c2) {
            return Double.compare(c1.getTonnage(), c2.getTonnage());
        }
    }

    @Override
    public String toString() {
        return "\nCargoPlane" +
                "model: " + this.getModel() +
                ", traveling distance = " +  String.format("%8.3f", this.getTravelingDistance()) +
                ", fuel consumption = " +  String.format("%8.3f", this.getFuelConsumption()) +
                ", price = " +  String.format("%8.3f", this.getPrice()) +
                ", lifespan = " +  String.format("%8.3f", this.getLifespan()) +
                ", tonnage = " + String.format("%8.3f", tonnage);
    }
}
